export default {
	methods: {
		toHome() {
			uni.switchTab({
				url: '/pages/index/home/home'
			})
		},
		goBack() {
			var pages = getCurrentPages();
			if (pages.length > 1) {
				uni.navigateBack({
					delta: 1
				});
			} else {
				uni.switchTab({
					url: '/pages/index/mine/mine'
				})
			}
		},
		// 判断是否为会员
		isVip() {
			if (this.$store.state.userInfo.vipExpireTime > new Date()
				.getTime() /
				1000 || !uni.getStorageSync('config')['client.pay.enable']) {
				return true
			}
			return false
		},

		goRoute(url, obj) {
			this.$u.route(url, obj)
		},
		goHtml(e) {
			console.log(e)
			// #ifdef APP
			plus.runtime.openWeb(e)
			// #endif
			// #ifdef MP
			this.goRoute('/packageA/pages/webView/webView', {
				fileUrl: e
			})
			// #endif
		},
		// 校验会员身份跳转到
		goItemDetail(url, obj) {
			if (this.isVip()) {
				if(this.isBindPhone()) return false
				this.goRoute(url, obj)
			} else {
				uni.navigateTo({
					url: '/packageA/pages/vipCenter/vipCenter'
				})
			}
		},
		// 校验购买会员后是否绑定手机号
		isBindPhone(){
			if (!this.$store.state.userInfo.phone && uni.getStorageSync('config')['client.pay.enable']) {
				uni.showToast({
					title: "请绑定手机号以防会员信息丢失",
					icon: 'none'
				})
				setTimeout(() => {
					// #ifdef MP
					this.goRoute('/pages/index/login/login')
					// #endif
					// #ifdef APP || APP-PLUS
					this.goRoute('/packageA/pages/login/login')
					// #endif
				}, 1500)
				return true
			}
		},
		goApp() {
			if (uni.getStorageSync('config')['client.pay.enable']) {
				this.$store.commit('updateVipagree', true)
			}
		},
		// 初始化接口
		async launch() {
			let data = uni.getStorageSync('saveAllList')
			console.log(data)
			console.log(uni.getStorageSync('idfa'))
			await this.$api.launch({
				oaid: '',
				idfa: uni.getStorageSync('idfa') || '',
				imei: '',
				ua: '',
				clickId: uni.getStorageSync('click_id') || ''
			}).then(res => {
				console.log(res);
				if (res.data.code == 1004) {
					uni.removeStorageSync('Token')
					return this.launch()
				}
				uni.setStorageSync('launch', res.data.data)
				uni.setStorageSync('config', res.data.data.config)
				if (!uni.getStorageSync('Token')) {
					uni.setStorageSync('Token', res.data.data.token)
				}
			})
		},

		copyText(text) {
			console.log(text)
			uni.setClipboardData({
				data: text,
				success(res) {
					console.log(res)
					uni.showToast({
						title: '复制成功',
						icon: 'none'
					})
				},
				fail(err) {
					console.log(err)
				}
			})
		}

	}
}